package cn.icatw.blog.service;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class CsdnArticleService {
    //@Autowired
    //private CsdnArticleRepository csdnArticleRepository;

    public void saveCsdnArticle(String csdnUrl) {
        try {
            Document doc = Jsoup.connect(csdnUrl).get();
            String title = doc.select("h1.title-article").text(); // 获取文章标题
            String content = doc.select("div.article_content").html(); // 获取文章正文内容（HTML格式）
            System.out.println("title: " + title);
            System.out.println("content: " + content);
            //CsdnArticle article = new CsdnArticle();
            //article.setTitle(title);
            //article.setContent(content);
            //csdnArticleRepository.save(article);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
